import { defineStore } from 'pinia';
import { getUserInfo } from '../api/userInfo';
export const userInfoStore = defineStore('userInfo', {
	state: () => {
		return {
			imageUrl: '',
			name: '',
			sex: '',
			department: '',
			identity: '',
			account: '',
			email: ''
		}
	},
	actions: {
		// 获取用户信息
		async getUserInfo (id) {
			const res = await getUserInfo(id)
			this.imageUrl = res.image_url
			this.name = res.name
			this.sex = res.sex
			this.department = res.department
			this.identity = res.identity
			this.account = res.account
			this.email = res.email
			sessionStorage.setItem('id', res.id)
		}
	},
	persist: {
		enable: true,
		key: 'userInfo',
		storage: localStorage,
	}
});
